package net.towee.model.account.impl;

import java.util.ArrayList;
import java.util.List;

import net.towee.model.account.PrivacyRule;
import net.towee.model.account.RuleDestination;
import net.towee.model.account.RuleItem;

import com.google.code.morphia.annotations.Embedded;
import com.google.code.morphia.annotations.PostLoad;
import com.google.code.morphia.annotations.Reference;

/**
 * Rule of privacy. This rule using for filtering account profile
 * information for any group of users.
 * @author c58
 */
@Embedded
public class PrivacyRuleImpl implements PrivacyRule {	
	// Reference to object of rule destination
	@Reference private RuleDestination dest;
	
	// List of rule items
	private List<RuleItem> items;
	
	public PrivacyRuleImpl(){}
	public PrivacyRuleImpl(RuleDestination dest){
		this.items = new ArrayList<RuleItem>();
		this.dest = dest;
	}
	
	@PostLoad
	private void createEmptyArrays() {
		if(items == null)
			items = new ArrayList<RuleItem>();
	}

	@Override
	public RuleDestination getDestination() {
		return dest;
	}

	@Override
	public List<RuleItem> getItems() {
		return items;
	}

	@Override
	public void addItem(RuleItem item) {
		this.items.add(item);
	}

	@Override
	public void deleteItem(RuleItem item) {
		this.items.remove(item);
	}

	@Override
	public boolean hasItem(RuleItem item) {
		return this.items.contains(item);
	}

}
